package com.automobile.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.automobile.dao.CarBrandDao;
import com.automobile.dao.CarTypeDao;
import com.automobile.dao.CategoryDao;
import com.automobile.domain.CarBrand;
import com.automobile.domain.CarType;
import com.automobile.domain.Category;
import com.automobile.service.CategoryService;

@CacheConfig(cacheManager = "redisCacheManager")
@Service("categoryService")
public class CategoryServiceImpl implements CategoryService{
	
	@Autowired
	private CategoryDao categoryDao;

    @Autowired
    private CarBrandDao carBrandDao;

    @Autowired
    private CarTypeDao carTypeDao;

    @Cacheable(value = {"category"})
	public List<Category> findCategoryAll() {
        return categoryDao.findCategoryAll();
	}

    @Cacheable(value = {"carBrand"})
	public List<CarBrand> findCarBrandAll() {
        return carBrandDao.findCarBrandAll();
	}

    @Cacheable(value = {"carType"})
	public List<CarType> findCarTypeAll() {
        return carTypeDao.findCarTypeAll();
	}



    @Cacheable(value = {"category"},key = "#name")
	public int findCategoryIdByName(String name) {
		int id = categoryDao.findIdByName(name);
		return id;
	}

    @Cacheable(value = {"carBrand"},key = "#name")
	public int findCarBrandIdByName(String name) {
		int id = carBrandDao.findIdByName(name);
		return id;
	}

    @Cacheable(value = {"carType"},key = "#name")
	public int findCarTypeIdByName(String name) {
		int id = carTypeDao.findIdByName(name);
		return id;
	}

}
